<!DOCTYPE html>
<html lang="en">
<head>
  <title>浩然金融中心管理平台</title>
  <meta charset="utf-8">
  <meta content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0"
        name="viewport">
  <#include "/common/csslib.html">
</head>
<body>
<div class="main-wrapper">
  <!-- start: MAIN CONTAINER -->
  <div class="main-container inner">
    <!-- start: PAGE -->
    <div class="main-content">
      <div class="container">
        <div class="row h-main-search">
          <form action="javascript:;" method="post">
            <div class="pull-right h-btn-group">
              <button class="btn btn-info" id="return-btn" onclick="SystemDataEntryMgr.returnIndex()"><i
                      class="fa fa-mail-reply">&nbsp;&nbsp;</i>返回
              </button>
              <button class="btn btn-info" id="save" onclick="SystemDataEntryMgr.submitForm()" type="button"><i
                      class="fa fa-save">&nbsp;&nbsp;</i>保存
              </button>
            </div>
          </form>
        </div>

        <div class="form-horizontal  h-form-warp">
          <div class="h-msg-title h-table-header">
            <strong>数据条目信息<label style="color:red">(相同的数据条目编码、数据条目类型将不会录入)</label></strong>
          </div>
          <form action="/systemDataEntry/saveSystemDataEntry" class="form-horizontal" id="systemDataEntryForm"
                method="post" role="form">
            <input id="operation" name="operation" type="hidden" value="${operation!}"/>
            <input id="id" name="id" type="hidden" value="${systemDataEntry.id!}"/>
            <input id="projectId" name="projectId" type="hidden" value="${systemProjectInfo.id!}"/>
            <div class="form-group">
              <label class="col-sm-2 control-label">项目编码：</label>
              <div class="col-sm-2">
                <input class="form-control" id="projectCode" name="projectCode" readonly="readonly"
                       required="required" type="text" value="${systemProjectInfo.projectCode!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
              <div class="form-group">
                <@PageDict dict_name="dataBaseType" dict_desc="数据库类型" dict_key="std_database_type"
                dict_type="select" label_class="col-sm-2 control-label text-right" dict_class="col-sm-2"
                required="required" />
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">数据库url：</label>
              <div class="col-sm-2">
                <input class="form-control" id="jdbcUrl" name="jdbcUrl" required="required" type="text"
                       value="${systemDataEntry.dataCode!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
              <label class="col-sm-2 control-label">数据库驱动类：</label>
              <div class="col-sm-2">
                <input class="form-control" id="jdbcDriverClass" name="jdbcDriverClass" required="required"
                       type="text" value="${systemDataEntry.dataName!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
            <div class="form-group">
              <label class="col-sm-2 control-label">数据库用户名：</label>
              <div class="col-sm-2">
                <input class="form-control" id="jdbcUserName" name="jdbcUserName" required="required"
                       type="text" value="${systemDataEntry.dataName!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
              <label class="col-sm-2 control-label">数据库密码：</label>
              <div class="col-sm-2">
                <input class="form-control" id="jdbcUserPassword" name="jdbcUserPassword" required="required"
                       type="password" value="${systemDataEntry.dataLength!}"/>
              </div>
              <div class="col-sm-1">
                <span class="required">*</span>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
    <!-- end: PAGE -->
  </div>
  <!-- end: MAIN CONTAINER -->
</div>
<#include "/common/jslib.html">
<!-- form页面js -->
<script type="text/javascript">
    $(function () {
        // 页面操作类型：add(添加)-edit(编辑)-view(查看)
        var operation = $("#operation").val();
        var api = frameElement.api, W = api.opener;
        SystemDataEntryMgr = {
            // 初始化
            init: function () {
                // 查看的时候不显示保存按钮
                if (operation == "view") {
                    Jmts.setFormReadOnly();
                    $("#save").hide();
                }
                api.button({
                    id: 'cancel',
                    name: '关闭'
                });
                initDict(DICTURL, FORM, operation);
            },
            // init end

            // 提交数据
            submitForm: function () {
                //提交之前校验数据条目是否已经存在（编码和数据类型都相同）
                var dataCode = $("#dataCode").val();
                var dataType = $("#dataType").val();
                var id = $("#id").val();
                var data = {
                    id: id,
                    dataCode: dataCode,
                    dataType: dataType
                }
                var url = "/systemDataEntry/checkDataEntry";
                Jmts.ajaxPost(url, data, function (result) {
                    if (result.success) {
                        Jmts.ajaxSubmit(document.getElementById("systemDataEntryForm"), function (result) {
                            var operation = result.operation;
                            if (result.success) {
                                Jmts.succTips(result.msg);
                                if (operation == 'add') {
                                    SystemDataEntryMgr.returnIndex();
                                } else if (operation == 'edit') {
                                    window.location.reload();
                                }
                            } else {
                                Jmts.errorTips(result.msg);
                            }
                        });
                    } else {
                        Jmts.warnTips(result.msg);
                    }
                })
                return false;
            },
            // submitForm end
            //返回
            returnIndex: function () {
                var projectId = $("#projectId").val();
                window.location.href = "/systemDataEntry/query?projectId=" + projectId;
            }
        };
        // 执行初始化
        SystemDataEntryMgr.init();
        // 前台验证表单
        $("#systemDataEntryForm").validate();
    });
</script>
</body>
</html>
